package top.my.db;

import io.vertx.core.AbstractVerticle;
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.RedisAPI;
import org.apache.log4j.Logger;

/**
 * A verticle setting and reading a value in Redis.
 */
public class RedisServer extends AbstractVerticle {
    final Logger logger = Logger.getLogger(RedisServer.class);
    public static RedisServer redisServer;
    public RedisAPI redis;

    public RedisServer() {
        redisServer = this;
    }

    @Override
    public void start() {
        // 客户端处理 REDIS URLs。
        // 规范的数据库URL，密码是 URL 授权的密码字段。
        Redis client = Redis.createClient(vertx, "redis://@127.0.0.1:6379/1");
        redis = RedisAPI.api(client);
        client.connect().onSuccess(result -> {
                    logger.info("Retrieved value: " + result);
                })
                .onFailure(err -> {
                    logger.info("Connection or Operation Failed " + err);
                });

    }
}
